home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Interfaces & Libraries / Interfaces / CIncludes / generic.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-05  |  2.0 KB  |  62 lines  |  [TEXT/MPS ]

  1. /*
  2.     generic.h -- Macros for use with <iomanip.h>.
  3.     
  4.     Copyright Apple Computer,Inc.    1994-1995
  5.     All rights reserved.
  6.  
  7. */
  8.  
  9. #ifndef __GENERIC__
  10. #define __GENERIC__        1
  11.  
  12. /*
  13.  * macros to paste tokens together to form new names
  14.  */
  15.  
  16. #if defined(applec) || defined(powerc) || defined(__SC__)
  17.  
  18. /*
  19.  * ANSI C preprocessors will not expand the arguments to a macro;
  20.  * so we need to add a level of indirection to allow macro expansion of
  21.  * arguments.  (Reiser preprocessors allowed the first arg to be expanded;
  22.  * this method will allow both to be expanded, which is better than none.)
  23.  */
  24. #define name2(a,b)           _name2_aux(a,b)
  25. #define _name2_aux(a,b)      a##b
  26. #define name3(a,b,c)         _name3_aux(a,b,c)
  27. #define _name3_aux(a,b,c)    a##b##c
  28. #define name4(a,b,c,d)       _name4_aux(a,b,c,d)
  29. #define _name4_aux(a,b,c,d)  a##b##c##d
  30.  
  31. #else 
  32.  
  33. #endif
  34.  
  35. #if defined(applec) && !defined(__SC__)
  36.  
  37. // Alas, MPW C++ doesn't have an ANSI C conformant preprocessor, so
  38. //  the AT&T code as given doesn't work. The code below will work for 
  39. //  MPW C++, but **NOT** for a compiler with an ANSI C conformant
  40. //  preprocessor because the preprocessor isn't supposed to expand 
  41. //  operands of ##. Undefine applec to use this header with other
  42. //  compilers. Thanks to Allen Cecil for the suggested "fix". 
  43. # define declare(a,t)        a##declare(t)
  44. # define implement(a,t)      a##implement(t)
  45. # define declare2(a,t1,t2)   a##declare2(t1,t2)
  46. # define implement2(a,t1,t2) a##implement2(t1,t2)
  47. #else /* applec */
  48. #define declare(a,t) name2(a,declare)(t)
  49. #define implement(a,t) name2(a,implement)(t)
  50. #define declare2(a,t1,t2) name2(a,declare2)(t1,t2)
  51. #define implement2(a,t1,t2) name2(a,implement2)(t1,t2)
  52.  
  53. #endif
  54.  
  55. extern genericerror(int, char*);
  56. typedef int (*GPT)(int, char*);
  57. #define set_handler(generic,type,x) name4(set_,type,generic,_handler)(x)
  58. #define errorhandler(generic,type) name3(type,generic,handler)
  59. #define callerror(generic,type,a,b) (*errorhandler(generic,type))(a,b)
  60.  
  61. #endif    /* __GENERIC__ */
  62.